#pragma once
#include <functional>
#include <vector>
#include<ctime>

using task_t = std::function<void()>;

class Task
{
    public:
    Task()
    {
        srand(time(nullptr));
        tasks.push_back([](){std::cout << "sub process[" << getpid() << " "
            "] 执行访问数据库的任务\n" << std::endl;});
        tasks.push_back([](){std::cout << "sub process[" << getpid() << " "
            "] 执行url解析\n" << std::endl;});
        tasks.push_back([](){std::cout << "sub process[" << getpid() << " "
            "] 执行加密任务\n" << std::endl;});
        tasks.push_back([](){std::cout << "sub process[" << getpid() << " "
            "] 执行数据持久化任务\n" << std::endl;});
    }

    int SelectTask()
    {
        int num = rand() % tasks.size();
        return num;
    }

    void Excute(unsigned int num)
    {
        if(num >= tasks.size() || num < 0)
        return;
        tasks[num]();
    }

    ~Task()
    {}

    private:
    std::vector<task_t> tasks;
};
Task ts;